<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;
use think\facade\Config;

// 定义一个匿名函数
Route::get('think', function () {
    // 返回字符串'hello,ThinkPHP6!'
    return 'hello,ThinkPHP6!';
});

Route::get('hello/:name', 'index/hello');

// 定义一个匿名函数，返回一个响应对象，该对象包含一个头部信息，该头部信息由Config类中的cors.headers配置项获取
Route::options('*', function () {
    return response()->header(Config::get('cors.headers'));
})->allowCrossDomain();

// 用户认证路由
Route::post('login', '\app\controller\common\AuthController@login')->name('login');
Route::post('logout', '\app\controller\common\AuthController@logout')->name('logout');


// 公共路由
Route::get('index', '\app\controller\common\IndexController@index')->name('index');
Route::get('honor-wall', '\app\controller\common\IndexController@honorWall')->name('honorWall');
Route::get('scoreboard', '\app\controller\common\IndexController@scoreboard')->name('scoreboard');
Route::get('career-showcases', '\app\controller\common\IndexController@careerShowcases')->name('careerShowcases');

// 管理员路由
Route::group('admin', function () {
    // 项目管理
    Route::post('projects', '\app\controller\admin\ProjectController@create');
    // 荣誉管理
    Route::resource('honors', '\app\controller\admin\HonorController');
    // 职业风采
    Route::resource('careers', '\app\controller\admin\CareerController');

    Route::group('club', function () {
        Route::get('index', '\app\controller\admin\ClubController@index');          // 获取所有社团列表
        Route::get('read/:id', '\app\controller\admin\ClubController@read');         // 获取社团详情
        Route::post('save', '\app\controller\admin\ClubController@save');          // 创建社团
        Route::put('update/:id', '\app\controller\admin\ClubController@update');       // 更新社团
        Route::delete('delete/:id', '\app\controller\admin\ClubController@delete');    // 删除社团
        Route::post('assignMember', '\app\controller\admin\ClubController@assignMember'); //分配社团成员
        Route::post('removeMember', '\app\controller\admin\ClubController@removeMember'); //移除社团成员
        Route::get('members', '\app\controller\admin\ClubController@members'); //获取社团成员
    });
    Route::post('user', '\app\controller\admin\UserController@addUser');

    // 指导老师管理
    Route::post('teachers', '\app\controller\admin\TeacherController@addTeacher');
    Route::get('teachers', '\app\controller\admin\TeacherController@listTeacher');
    Route::get('teachers/:id', '\app\controller\admin\TeacherController@getTeacher');
    Route::put('teachers/:id', '\app\controller\admin\TeacherController@updateTeacher');
    Route::delete('teachers/:id', '\app\controller\admin\TeacherController@deleteTeacher');


})->middleware([
    \app\middleware\AuthMiddleware::class,
    \app\middleware\AdminAuthMiddleware::class
]);
//});
// 学员路由
Route::group('student', function () {
    // 个人资料
    Route::post('profile', '\app\controller\student\ProfileController@submitHonor');
    // 训练任务
    Route::get('tasks', '\app\controller\student\TaskController@todayTasks');
    Route::post('tasks', '\app\controller\student\TaskController@submitLog');
})->middleware([
    \app\middleware\AuthMiddleware::class,
    \app\middleware\StudentAuthMiddleware::class
]);

// 教师路由
Route::group('teacher', function () {
    // 训练任务管理
    Route::resource('tasks', '\app\controller\teacher\TrainingController');
    // 资源管理
    Route::resource('resources', '\app\controller\teacher\ResourceController');
    // 成员管理
    Route::get('members', '\app\controller\teacher\MemberController@members');
    Route::post('member', '\app\controller\teacher\MemberController@addMember');// 添加项目成员
    Route::get('member/:userId', '\app\controller\teacher\MemberController@getMemberInfo');// 获取成员详细信息
    Route::put('verifyInfoChange/:id', '\app\controller\teacher\MemberController@verifyInfoChange');// 审核成员信息变更

})->middleware([
    \app\middleware\AuthMiddleware::class,
    \app\middleware\TeacherAuthMiddleware::class
]);

// 资源路由
Route::get('resources/:id', 'resource/ResourceController@detail');
Route::get('certifications', 'resource/ResourceController@listCertifications');